package com.pronosticnews.client.admin;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.pronosticnews.client.admin.navigation.AppPlaceHistoryMapper;
import com.pronosticnews.client.admin.navigation.EditActivityMapper;
import com.pronosticnews.client.admin.navigation.ListActivityMapper;
import com.pronosticnews.client.admin.navigation.sync.AsyncActivityManager;
import com.pronosticnews.client.admin.place.AccueilPlace;
import com.pronosticnews.client.admin.view.main.MainScreen;
import com.pronosticnews.client.admin.view.main.MainScreenImpl;

public class PronosticnewsAdmin implements EntryPoint {

	public void onModuleLoad() {
		ClientFactory clientFactory = GWT.create(ClientFactory.class);

		// initialisation de lecran principal
		MainScreen mainScreen = new MainScreenImpl(clientFactory);

		// list navigation
		ListActivityMapper listActivityMapper = new ListActivityMapper(
				clientFactory);
		AsyncActivityManager listActivityManager = new AsyncActivityManager(
				listActivityMapper, clientFactory.getEventBus());
		listActivityManager.setDisplay(mainScreen.getListPanel());

		// edit navigation
		EditActivityMapper editActivityMapper = new EditActivityMapper(
				clientFactory);
		AsyncActivityManager editActivityManager = new AsyncActivityManager(
				editActivityMapper, clientFactory.getEventBus());
		editActivityManager.setDisplay(mainScreen.getEditPanel());

		// history
		AppPlaceHistoryMapper historyMapper = GWT
				.create(AppPlaceHistoryMapper.class);

		PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(
				historyMapper);
		historyHandler.register(clientFactory.getPlaceController(),
				clientFactory.getEventBus(), new AccueilPlace());

		// on ajout lecran principal dans le root panel
		RootLayoutPanel.get().add(mainScreen.getMain());
	}
}
